package com.xihuanjun.sdk.dao;

import com.fasterxml.jackson.core.sym.NameN;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xihuanjun.sdk.entity.JSTInout;
import com.xihuanjun.sdk.entity.JSTOut;
import com.xihuanjun.sdk.entity.JSTPageData;
import com.xihuanjun.sdk.entity.JSTRefund;
import com.xihuanjun.sdk.enums.JSTMethod;
import com.xihuanjun.sdk.util.JsonUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.*;

/**
 * Copyright (C), 2024-09-27
 * FileName: JSTRefundDao
 * Author:   溪浣君
 * Date:     2024-09-27 10:40
 * Description: 售后单
 */
@Component
public class JSTRefundDao extends  BaseDao{


    /**
     * 获取售后单详情
     * @param refundId
     * @return
     * @throws IOException
     */
    public JSTRefund get(int refundId) throws IOException {
        int[] arr={refundId};
        Map map=new HashMap();
        map.put("as_ids",arr);
        List<JSTRefund> jstRefunds = this.jstListQuery(map, JSTMethod.JST_REFUND_SINGLE_QUERY, new TypeReference<List<JSTRefund>>() {});
        return getOneFromList(jstRefunds);
    }

    /**\     *
     * https://open.jushuitan.com/document.aspx?doc_id=2356
     * @param shopId
     * @param time1 修改时间开始
     * @param time2 修改时间结束
     * @param pageIndex
     * @param pageSize
     * @param status "Confirmed"
     * @return
     */
    public List<JSTRefund> getQMList(String shopId,
                                     String time1,String time2,
                                     int pageIndex,int pageSize,
                                     String status,String type,String soId){
        HashMap<String, String> map=new HashMap<>();
        map.put("data_type","0");//时间类型：修改时间
        if(StringUtils.hasText(status)){//售后单状态
            map.put("status",status);
        }
        if(StringUtils.hasText(type)){//售后单类型
            map.put("type",type);
        }
        if(StringUtils.hasText(shopId)){//店铺编号
            map.put("shop_id",shopId);
        }
        map.put("page_index",pageIndex+"");
        map.put("page_size",pageSize+"");
        if(StringUtils.hasText(time1)){
            map.put("start_time",time1);
        }
        if(StringUtils.hasText(time2)){
            map.put("end_time",time2);
        }
        if(StringUtils.hasText(soId)){
            map.put("so_ids",soId);
        }
        try {
            List<JSTRefund> jstRefunds = this.qmListQuery(map, JSTMethod.QM_REFUND_LIST_QUERY, new TypeReference<List<JSTRefund>>() {
            });
            return jstRefunds;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
